package com.example.controller;

import com.example.entity.RestBean;
import com.example.entity.vo.response.WeatherVO;
import com.example.service.WeatherService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: shenjianZ
 * @Date: 2024/4/30 下午2:51
 * @Description:
 */

@RestController
@RequestMapping("/api/forum")
public class ForumController {

    @Resource
    private WeatherService weatherService;

    @GetMapping("/weather")
    public RestBean<WeatherVO> weather(double longitude, double latitude) {
        WeatherVO weatherVo = weatherService.fetchWeather(longitude, latitude);
        return weatherVo == null ?
                RestBean.failure(400, "获取天气失败") : RestBean.success(weatherVo);
    }
}
